package com.hjl.service.impl;

import com.hjl.dao.AnnoDao;
import com.hjl.dao.impl.AnnoDaoImpl;
import com.hjl.domain.Anno_inf;
import com.hjl.domain.PageBean;
import com.hjl.service.AnnoService;
import java.util.List;
import java.util.Map;

/**
 * 公告业务逻辑层实现类
 *
 * @author Lenovo
 * @version 1.0
 * @date 2021/10/8 20:35
 */
public class AnnoServiceImpl implements AnnoService {
    private AnnoDao annoDao = new AnnoDaoImpl();

    /**
     * 分页查询
     *
     * @param currentPageString 当前页
     * @param rowsString        行数
     * @param condition         状态
     * @return com.hjl.domain.PageBean<com.hjl.domain.Anno_inf>
     * @author Lenovo
     * @date 2021/10/8 20:36
     */
    @Override
    public PageBean<Anno_inf> findAnnoByPage(String currentPageString, String rowsString, Map<String, String[]> condition) {
        int currentPage = Integer.parseInt(currentPageString);
        int rows = Integer.parseInt(rowsString);
        int totalCount = annoDao.findTotalCount(condition);
        int start = (currentPage - 1) * rows;
        List<Anno_inf> list = annoDao.findByPage(start, rows, condition);
        int totalPage = totalCount % rows == 0 ? totalCount / rows : (totalCount / rows + 1);

        //创建PageBean并放入数据，返回
        return new PageBean<>(totalCount, totalPage, list, currentPage, rows);
    }

    /**
     * 删除选中
     *
     * @param ids 选中的id
     * @author Lenovo
     * @date 2021/10/8 20:36
     */
    @Override
    public void delSelect(String[] ids) {
        if (ids != null && ids.length > 0) {
            for (String id : ids) {
                annoDao.delAnno(Integer.parseInt(id));
            }
        }
    }

    /**
     * 通过id查询
     *
     * @param id ID
     * @return com.hjl.domain.Anno_inf
     * @author Lenovo
     * @date 2021/10/8 20:36
     */
    @Override
    public Anno_inf findAnnoById(String id) {
        return annoDao.findAnnoById(Integer.parseInt(id));
    }

    /**
     * 更新
     *
     * @param anno 公告对象
     * @author Lenovo
     * @date 2021/10/8 20:37
     */
    @Override
    public void updateAnno(Anno_inf anno) {
        annoDao.updateAnno(anno);
    }

    /**
     * 添加
     *
     * @param anno 公告对象
     * @author Lenovo
     * @date 2021/10/8 20:37
     */
    @Override
    public void addAnno(Anno_inf anno) {
        annoDao.addAnno(anno);
    }
}
